<?php namespace web\home\controller;
/**
 * Created by PhpStorm.
 * User: qianchenmiao
 * Date: 2016/10/23
 * Time: 20:12
 * 个人中心
 */
class MyCenter extends Common{
	public function index(){
//				分配title数据
		$conf=['title'=>'订单中心'];
		View::with('conf',$conf);
//				分配js
		$js=['nav'=>"{{__ROOT__}}/resource/home/js/nav.js"];
//		获得当前登录用户的订单
		$huid=$_SESSION['homeUser']['uid'];
		$orderData=Db::table('order')->where('huid',$huid)->get();
//		p($orderData);
	foreach($orderData as $k=>$v){
//		p($v);
		$orderData[$k]['list']=Db::table('orderlist')->where('oid',$v['oid'])->get();
		if($v['orderState']==1){
			$orderData[$k]['orderState']='待付款';
		}elseif(['orderState']==2){
			$orderData[$k]['orderState']='待收货';
		}else{
			$orderData[$k]['orderState']='已完成';
		}

	}
		foreach($orderData as$k=>$v){
			foreach($v['list'] as $key=>$value){
//
				$gname=Db::table('goods')->where('gid',$value['gid'])->lists('gname,pic');
				foreach($gname as $kk=>$vv){
					$orderData[$k]['list'][$key]['gpic']=$vv;
					$orderData[$k]['list'][$key]['gname']=$kk;
				}
			}
		}

		View::with('orderData',$orderData)->with('js',$js)->make();
	}
	//取消订单
	public function delOrder(){
		$oid=q('oid',0,'intval');
		if($oid){
			Db::table('order')->where('oid',$oid)->delete();
			Db::table('orderlist')->where('oid',$oid)->delete();
			message('删除成功','index','success');
		}else{
			message('订单不存在','index','error');
		}
	}
}